package livingarea.actions_impl;

import livingarea.actions.SpawnType;
import livingarea.Members.Beast;
import livingarea.Members.Factory.AreaMemberFactory;
import livingarea.Members.Factory.PredatorFactory;
import livingarea.Members.Predator;

/**
 * Class incapsulate <code> spawn() </code> method and realized spawn action of
 * predator beast.
 *
 * @author Muzalevskiy Vitaliy
 */
public class PredatorSpawn implements SpawnType {

    /**<code> Beast </code> object that delegate object of current class.*/
    private Beast beast;

    /**
     * Constructor for current class.
     *
     * @param beast - <code> Beast </code> object that delegate object of 
     *      current class.
     */
    public PredatorSpawn(Beast beast) {
        this.beast = beast;
    }

    /**
     * Current method make pray beast to spawn after specified number of eaten
     * prays.
     */
    @Override
    public void spawn() {
        if (beast.getEatCount() >= Predator.EAT_TO_SPOWN) {
            AreaMemberFactory predatorFactory = new PredatorFactory();
            predatorFactory.create(beast.getLivingArea(), beast.getPosition());
            beast.resetEatCount();
            beast.getLivingArea().getStatistics().increasePredatorCount();
        }
    }
}
